package Question1;

public enum MatrixSumEnum implements SumInterface{
    ROW("所有行的和"){
        @Override
        public int[] sum(int[][] Arr) {
            int Length = Arr[0].length;
            int[] Sum = new int[Length];
            for(int i = 0;i < Length;i++) {
                for(int j = 0;j < Length;j++) {
                    Sum[i] += Arr[i][j];
                }
            }
            return Sum;
        }
    },COLUMN("所有列的和"){
        @Override
        public int[] sum(int[][] Arr) {
            int Length = Arr[0].length;
            int[] Sum = new int[Length];
            for(int i = 0;i < Length;i++) {
                for(int j = 0;j < Length;j++) {
                    Sum[i] += Arr[j][i];
                }
            }
            return Sum;
        }
    },LEFTDIAGONAL("左对角线的和"){
        @Override
        public int[] sum(int[][] Arr) {
            int Length = Arr[0].length;
            int[] Sum = new int[1];
            for(int i = 0;i < Length;i++) {
                    Sum[0] += Arr[i][i];
            }
            return Sum;
        }
    },RIGHTDIAGONAL("右对角线的和"){
        @Override
        public int[] sum(int[][] Arr) {
            int Length = Arr[0].length;
            int[] Sum = new int[1];
            for(int i = 0,j = Length - 1;i < Length;i++,j--) {
                    Sum[0] += Arr[i][j];
            }
            return Sum;
        }
    };

    private final String desc;

    private MatrixSumEnum(String desc) {
        this.desc = desc;
    }

    public String getDesc() {
        return desc;
    }
}
